﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LdCms.Web.Controllers.API.Sms.V1
{
    using LdCms.Common.Extension;
    using LdCms.EF.DbModels;
    using LdCms.Web.Services;
    using LdCms.Plugins.Sms.Tencent;
    using System.Text;



    /// <summary>
    /// 
    /// </summary>
    [ApiVersion("1.0")]
    [ControllerName("sms/tencent/sms/callback")]
    public class SmsTencentSmsCallbackController : BaseApiController
    {
        private readonly IBaseApiManager BaseApiManager;
        public SmsTencentSmsCallbackController(IBaseApiManager BaseApiManager) : base(BaseApiManager)
        {
            this.BaseApiManager = BaseApiManager;
        }
        private TencentSmsCallbackHelper TencentSmsCallbackHelper
        {
            get
            {
                return new TencentSmsCallbackHelper();
            }
        }

        [HttpPost]
        [ActionName("status/notify.action")]
        public IActionResult GetStatusNotify(string uuid)
        {
            long logId = 0;
            try
            {
                string formValue = HttpContext.Request.GetInputStream();
                logId = BaseApiManager.SaveLogs(uuid, formValue);

                var result = TencentSmsCallbackHelper.GetSmsStatusCallbackPro();

                string responseResult = TencentSmsCallbackHelper.ResponseResult(0);

                return Result(logId, responseResult);
            }
            catch (Exception ex)
            {
                return Result(logId, ex.Message);
            }
        }

        [HttpPost]
        [ActionName("reply/notify.action")]
        public IActionResult GetReplyNotify(string uuid)
        {
            long logId = 0;
            try
            {
                string formValue = HttpContext.Request.GetInputStream();
                logId = BaseApiManager.SaveLogs(uuid, formValue);

                var result = TencentSmsCallbackHelper.GetSmsReplyCallbackPro();

                string responseResult = TencentSmsCallbackHelper.ResponseResult(0);

                return Result(logId, responseResult);
            }
            catch (Exception ex)
            {
                return Result(logId, ex.Message);
            }
        }

    }
}